package com.jiangdong.eureka.consumer.controller;

import com.jiangdong.eureka.consumer.entitys.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/test")
public class ThymeleafTestController {

    @GetMapping("/model")
    public String home(Model model){
        Student student = new Student();
        student.setName("jiang");
        student.setAge(24);
        model.addAttribute("student",student);
        return "home";
    }

    @GetMapping("/modelAndView")//不需要使用@ResponseBody注解
    public ModelAndView home(ModelAndView modelAndView){
        Student student = new Student();
        student.setName("sai");
        student.setAge(24);
        modelAndView.addObject("student",student);
        modelAndView.setViewName("home");
        return modelAndView;
    }

}
